package com.fbty.mt.action.admin;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fbty.base.action.BaseAction;
import com.fbty.base.domain.Page;
import com.fbty.mt.domain.Announcement;
import com.fbty.mt.domain.News;
import com.fbty.mt.domain.OnlyIpInfo;
import com.fbty.mt.service.IpService;
import com.fbty.mt.service.NewsService;
import com.fbty.mt.service.OtherService;
/**
 * 系统公告和新闻
 * @author thinkpad
 *
 */
@SuppressWarnings("serial")
public class NewsAction extends BaseAction{
	
	private Page page;
	
	private int pageNo=1;
	
	private int pageSize=20;
	
	private News news;
	private String context; 
	private String title;
	private Integer type;
	private NewsService newsService;
	private Announcement ann;

	/**
	 * 分布显示新闻
	 * @return
	 * @throws Exception
	 */
	public String pageNews() throws Exception {
		Map parms=new HashMap();
		page = newsService.pageNews(pageNo, pageSize, parms);
		return SUCCESS;
	}
	public String goToAddNewsPage() throws Exception {
		return SUCCESS;
	}
	/**
	 * 保存或更新新存
	 * @return
	 * @throws Exception
	 */
	public String saveNews() throws Exception {
		if(news != null && news.getId() != null) {
			news.setCreatedate(new Date());
			newsService.updateNew(news);
		} else {
			news.setCreatedate(new Date());
			news.setType(0);
			newsService.saveNews(news);
		}
		return SUCCESS;
	}
	/**
	 * 改变消息状态是否发布到前台
	 * @return
	 * @throws Exception
	 */
	public String updateNewsState() throws Exception {
		newsService.updateNewsState(news.getId());
		return SUCCESS;
	}
	/**
	 * 删除新闻
	 * @return
	 * @throws Exception
	 */
	public String delNews() throws Exception {
		newsService.deleteNews(news.getId());
		return SUCCESS;
	}
	
	
	/**
	 * 分布显示公告
	 * @return
	 * @throws Exception
	 */
	public String pageAnnouncement() throws Exception {
		Map parms=new HashMap();
		page = newsService.pageAnn(pageNo, pageSize, parms);
		return "success";
	}
	public String goToAddAnnPage() throws Exception {
		return SUCCESS;
	}
	/**
	 * 保存或更新新存
	 * @return
	 * @throws Exception
	 */
	public String saveAnn() throws Exception {
		if(ann != null && ann.getId() != null) {
			ann.setCreatedate(new Date());
			newsService.updateAnn(ann);
		} else {
			ann.setCreatedate(new Date());
			ann.setType(0);
			newsService.saveAnn(ann);
		}
		return SUCCESS;
	}
	/**
	 * 改变消息状态是否发布到前台
	 * @return
	 * @throws Exception
	 */
	public String updateAnnState() throws Exception {
		newsService.updateAnnState(ann.getId());
		return SUCCESS;
	}
	/**
	 * 删除新闻
	 * @return
	 * @throws Exception
	 */
	public String delAnn() throws Exception {
		newsService.deleteAnn(ann.getId());
		return SUCCESS;
	}
	
	
	
	public News getNews() {
		return news;
	}
	public void setNews(News news) {
		this.news = news;
	}
	public NewsService getNewsService() {
		return newsService;
	}
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}


	public Page getPage() {
		return page;
	}


	public void setPage(Page page) {
		this.page = page;
	}


	public int getPageNo() {
		return pageNo;
	}


	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public String getContext() {
		return context;
	}
	public void setContext(String context) {
		this.context = context;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public Announcement getAnn() {
		return ann;
	}
	public void setAnn(Announcement ann) {
		this.ann = ann;
	}
	
}
